home *** CD-ROM | disk | FTP | other *** search
- /*
- * MenuBar.c
- *
- * This source code is absolutely free. You may use this code in anything
- * you write, commercial or otherwise, completely free of obligation.
- *
- * This code is based on the pascal code written by Earle R. Horton found
- * in the USENET Macintosh Programmer's Guide Volume I (10/18/90) on page
- * 258. This version, in addition to having been ported to THINK C, has
- * been altered so that MBarInit does not have to be explicitly called by
- * the user; instead, it is called the first time MBarHide is called.
- *
- */
-
- #include "screen.h"
-
- static void MBarInit( void );
- void MBarHide( void );
- void MBarRestore( void );
-
- static short saveMBarHeight; /* Copy of low memory global */
- /* variable MBarHeight */
- static RgnHandle saveGrayRgn; /* Copy of GrayRgn */
- static char hidden = false; /* true if the menu bar is */
- /* currently hidden */
- static Rect MBarRect; /* Rect enclosing the menu bar */
- static char init = false; /* true if initialization */
- /* has been called */
-
-
- /*
- * MBarInit
- *
- * Set up global variables.
- *
- */
-
- static void MBarInit( void )
- {
-
- init = true;
-
- saveMBarHeight = *((short *) 0xBAA);
-
- SetRect( &MBarRect,
- qd.screenBits.bounds.left,
- qd.screenBits.bounds.top,
- qd.screenBits.bounds.right,
- qd.screenBits.bounds.top + saveMBarHeight );
-
- }
-
-
-
- /*
- * MBarHide
- *
- * Hides the menu bar. This procedure changes the values of
- * low memory global variables, so compatibility with future
- * versions of system software should be considered unreliable.
- *
- */
-
- void MBarHide( void )
- {
-
- RgnHandle MBarRgn;
- WindowPeek theWindow;
-
-
- /* Set up global variables */
-
- if ( ! init ) {
- MBarInit();
- }
-
-
- /* Do nothing if the menu bar is already hidden */
-
- if ( hidden ) {
- return;
- }
-
-
- /* Initialize some variables */
-
- hidden = true;
-
- saveGrayRgn = NewRgn();
- MBarRgn = NewRgn();
-
-
- /* Set the low memory variable MBarHeight to zero */
-
- *((short *) 0xBAA) = 0;
-
-
- /* Save the old GrayRgn */
-
- CopyRgn( GetGrayRgn(), saveGrayRgn );
-
-
- /* Add the area of the menu bar to the GrayRgn */
-
- RectRgn( MBarRgn, &MBarRect );
- UnionRgn( saveGrayRgn, MBarRgn, GetGrayRgn() );
-
-
- /* Update visRgn for any windows with newly exposed areas */
-
- theWindow = (WindowPeek) FrontWindow();
- PaintOne( theWindow, MBarRgn );
- PaintBehind( theWindow, MBarRgn );
- CalcVis( theWindow );
- CalcVisBehind( theWindow, MBarRgn );
-
-
- /* Clean up */
-
- DisposeRgn( MBarRgn );
-
- }
-
-
-
- /*
- * MBarRestore
- *
- * Restores the menu bar and the GrayRgn to their former values.
- * This procedure should always be called when going into the
- * background under Multifinder.
- *
- */
-
- void MBarRestore( void )
- {
-
- WindowPeek theWindow;
-
-
- /* Do nothing if the menu bar is not hidden */
-
- if ( ! hidden ) {
- return;
- }
-
-
- hidden = false;
-
-
- /* Restore the GrayRgn to its original value */
-
- CopyRgn( saveGrayRgn, GetGrayRgn() );
-
-
- /* Restore MBarHeight to its original value */
-
- *((short *) 0xBAA) = saveMBarHeight;
-
-
- /* Update visRgn for any windows with newly covered areas */
-
- RectRgn( saveGrayRgn, &MBarRect );
- theWindow = (WindowPeek) FrontWindow();
- CalcVis( theWindow );
- CalcVisBehind( theWindow, saveGrayRgn );
-
-
- /* Dispose of our copy of the GrayRgn */
-
- DisposeRgn( saveGrayRgn );
-
-
- /* Make the menu bar visible */
-
- HiliteMenu( 0 );
- DrawMenuBar();
-
- }
-